﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using BLL.RF.ATETest;
using CrystalDecisions.CrystalReports.Engine;
using Model;

public partial class ViewTest_ViewYourself_ViewTestItem_Active : System.Web.UI.Page
{
    private ReportDocument doc = new ReportDocument();
    private TestItem_Active testItem;

    public ViewTest_ViewYourself_ViewTestItem_Active()
    {
        testItem = new TestItem_Active();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.CrystalReportViewer1.ShowLastPage();
            this.CrystalReportViewer1.ShowFirstPage();
            this.Page.Unload += new EventHandler(Page_Unload);
        }

    }
    public IList<TestItemInfo> GetData()
    {
        string str1 = (string)Session["productSN"];
        DateTime dt1 = (DateTime)Session["testTime"];
        return testItem.TestItem_Active_GetbySNDT(str1, dt1);         
    }

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {
        ForCrystalReport();
    }

    protected void ForCrystalReport()
    {
        doc.Load(Server.MapPath("ViewTestItem.rpt"));

        TextObject txtProductSN = (TextObject)doc.ReportDefinition.ReportObjects["Text4"];
        txtProductSN.Text = "腔体序列号：" + (string)Session["productSN"];
        TextObject txtTestTime = (TextObject)doc.ReportDefinition.ReportObjects["Text13"];
        txtTestTime.Text = "测试时间：" + ((DateTime)Session["testTime"]).ToString();
        TextObject txtProductTypeID = (TextObject)doc.ReportDefinition.ReportObjects["Text14"];
        txtProductTypeID.Text = "产品类型：" + (string)Session["ProductTypeID"];
        TextObject txtUserID = (TextObject)doc.ReportDefinition.ReportObjects["Text15"];
        txtUserID.Text = "测试员工号：" + (string)Session["UserID"];
        TextObject txtENAID = (TextObject)doc.ReportDefinition.ReportObjects["Text16"];
        txtENAID.Text = "矢网编号：" + (string)Session["ENAID"];
        TextObject txtSpecVersion = (TextObject)doc.ReportDefinition.ReportObjects["Text2"];
        txtSpecVersion.Text = "指标单版本：" + (string)Session["SpecVersion"];
        TextObject txtIsPass = (TextObject)doc.ReportDefinition.ReportObjects["Text17"];
        txtIsPass.Text = "是否通过：" + (string)Session["IsPass"];

        IList<TestItemInfo> list = GetData();
        doc.SetDataSource(list);
        this.CrystalReportViewer1.ReportSource = doc;
    }

    private void Page_Unload(object sender, EventArgs e)
    {
        doc.Dispose();
    }
}
